package com.model
{
	import com.model.vo.UserVO;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	
	import org.puremvc.as3.interfaces.IProxy;
	import org.puremvc.as3.patterns.proxy.Proxy;

	public class UserProxy extends Proxy implements IProxy
	{
		public static const NAME:String = 'UserProxy';
		public function UserProxy()
		{
			super(NAME,new ArrayCollection());
			addItem(new UserVO('李不凡','libufan@xingmo.com','123456'));
			addItem(new UserVO('蒯义刚','kuaiyigang@xingmo.com','123456'));
			addItem(new UserVO('方龙','fanglor@xingmo.com','123456'));
		}
		public function get users():ArrayCollection
		{
		    return data as ArrayCollection;
		}
		public function addItem(item:Object):void
		{		
		    users.addItem(item);
		}
		public function updateItem(item:Object):void
		{
		    var user:UserVO = item as UserVO;
		    Alert.show('修改成功');
		}
		public function deleteItem(item:Object):void
		{
		    var user:UserVO = item as UserVO;
		    for(var i:int=0;i<users.length;i++)
		    {
		        if(users[i].username == user.username)
		        {
		            users.removeItemAt(i);
		        }
		    }
		    Alert.show('删除成功');
		}
		public function isSubmit(item:Object):Boolean
		{
		    for(var i:int=0;i<users.length;i++)
			{
			    if(users[i].username == item.username)
			    {
			        return false;
			    }
			}
			return true;
		}	
	}
}